package com.lxq.LeetCode.maxArea;

public class Solution {
    public static void main(String[] args) {
        int[] height = {1,8,6,2,5,4,8,3,7};
        int res = maxArea(height);
        System.out.println(res);
    }

    public static int maxArea(int[] height) {
        int capacity = height.length;
        int res = 0;
        int i = 0, j = capacity - 1;
        while (i < j) {
            res = Math.max(res, Math.min(height[i], height[j]) * (j - i));
            if (height[i] < height[j]) {
                int temp = height[i];
                do {
                    i++;
                } while (height[i] < temp);
            } else {
                int temp = height[j];
                do {
                    j--;
                } while (height[j] < temp);
            }
        }

        return res;
    }
}
